package org.atlantis.datasink.cfg;

import org.atlantis.datasink.event.EventManager;
import org.w3c.dom.Element;

class QueueOptionFragment implements OptionFragment<Option> {

	private static final String QUEUE_LIMIT_ATTR = "queueLimit";
	private static final String WORKER_LIMIT_ATTR = "workerLimit";
	private static final String NAME_ATTR = "name";

	@Override
	public Option parse(Element optElm) throws Exception {
		int queueLimit = EventManager.DEFAULT_MESSAGE_LIMIT;
		int workerLimit = EventManager.DEFAULT_WORKER_LIMIT;
		String name = optElm.getAttribute(NAME_ATTR);

		if (optElm.hasAttribute(QUEUE_LIMIT_ATTR)) queueLimit = Integer.parseInt(optElm.getAttribute(QUEUE_LIMIT_ATTR));
		if (optElm.hasAttribute(WORKER_LIMIT_ATTR)) workerLimit = Integer.parseInt(optElm.getAttribute(WORKER_LIMIT_ATTR));

		EventManager.getInstance().create(name, queueLimit, workerLimit);

		return null;
	}
}
